package fr.ginvest.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity
@Table(name = "avancement")
public class Avancement implements Serializable {

	private static final long serialVersionUID = 8593929451673526538L;
	
	public enum Etat{EN_COURS, CLOTURE}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO) 
	private int id;
	
	@ManyToOne
	@JoinColumn(name="startup_fk",referencedColumnName="id",nullable=false)
	private Startup startup;
	
	@ManyToOne
	@JoinColumn(name="club_fk",referencedColumnName="id",nullable=false)
	private Club club;
	
	@Temporal(TemporalType.DATE)
	@Basic(optional=false)
	private java.util.Date dateDebut;
	
	@Temporal(TemporalType.DATE)
	private java.util.Date dateFin;
	
	@Enumerated(EnumType.STRING)
	@Column(length=8, nullable=false)
	private Etat etat;
	
	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name="avancement_fk",referencedColumnName="id")
	private Collection<Stade> stades = new ArrayList<Stade>();
	
	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name="avancement_fk",referencedColumnName="id")
	private Collection<Participation> participations = new ArrayList<Participation>();
	
	public Avancement() {}

	public Avancement(Startup startup, Club club) {
		super();
		this.startup = startup;
		this.club = club;
		this.dateDebut = new Date();
		this.etat = Etat.EN_COURS;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Avancement other = (Avancement) obj;
		if (id != other.id)
			return false;
		return true;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Etat getEtat() {
		return etat;
	}

	public void setEtat(Etat etat) {
		this.etat = etat;
	}

	public Startup getStartup() {
		return startup;
	}

	public void setStartup(Startup startup) {
		this.startup = startup;
	}

	public Club getClub() {
		return club;
	}

	public void setClub(Club club) {
		this.club = club;
	}

	public Collection<Stade> getStades() {
		return stades;
	}

	public void setStades(Collection<Stade> stades) {
		this.stades = stades;
	}
	
	public void addStade(Stade stade) {
		this.stades.add(stade);
	}

	public java.util.Date getDateDebut() {
		return dateDebut;
	}

	public void setDateDebut(java.util.Date dateDebut) {
		this.dateDebut = dateDebut;
	}

	public java.util.Date getDateFin() {
		return dateFin;
	}

	public void setDateFin(java.util.Date dateFin) {
		this.dateFin = dateFin;
	}

	public Collection<Participation> getParticipations() {
		return participations;
	}

	public void setParticipations(Collection<Participation> participations) {
		this.participations = participations;
	}
	
	public void addParticipation(Participation p) {
		this.participations.add(p);
	}

}
